package com.company.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @description: FutureTask
 * @author: ruoan
 * @date: 2020/10/24 14:33
 */

public class Thread14 {
    static String result="hello";
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("hho");

            }
        };

        FutureTask<String> task = new FutureTask<>(r1,result);
        Thread t = new Thread(task, "t");
        t.start();

        //main阻塞获得t的运行结果
        String s = task.get();
        System.out.println(s);
    }
}
